package jianzhiOffer;

import java.util.Arrays;
import java.util.Comparator;

//剑指 Offer 45. 把数组排成最小的数
public class Num45_minNumber {
    public String minNumber(int[] nums) {
      //转为字符串数组
        String []arr = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            arr[i] = String.valueOf(nums[i]);
        }
        //排序
        Arrays.sort(arr, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o1 + o2).compareTo(o2 + o1);
            }
        });
        String ret = "";
        for (String str : arr){
            ret += str;
        }
        return ret;

    }
}
